<?php
/* @var $this Controller */
$this->beginWidget('bootstrap.widgets.TbBox', array(
	'title' => $create ? "新建项目" : array($this->projectName => array('project/schema'), '修改索引结构'),
	'headerIcon' => 'icon-edit',
));
$this->widget('bootstrap.widgets.TbAlert', array(
	'block' => true, // display a larger alert block?
	'fade' => true, // use transitions?
	'closeText' => '×', // close link text - if set to false, no close link is displayed
	'alerts' => array('success', 'error', 'warning', 'info'),
));
?>
<div class="row-fluid">
	<?php	
	$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'horizontalForm',
		'type' => 'horizontal',
	));	/* @var TbActiveForm $form */
	echo $form->errorSummary($model);
	?>
	<table id="change-table">
		<tr>
			<td><?php echo $form->textFieldRow($model, 'projectName', array('readonly' => !$create)); ?></td>
			<td><?php echo $form->dropDownListRow($model, 'charset', $model->charsetOptions()); ?></td>
		</tr>
		<tr>
			<td><?php echo $form->textFieldRow($model, 'indexServer'); ?></td>
			<td><?php echo $form->textFieldRow($model, 'searchServer'); ?></td>
		</tr>
	</table>
	<table id="field-table" class="items table table-striped table-bordered">
		<tr>
			<th style="width:50px;">字段名称</th>
			<th>类型</th>
			<th>索引</th>
			<th>分词器</th>
			<th>截取长度</th>
			<th>权重</th>
			<th>精确</th>
		</tr>
		<?php foreach ($model->getFields() as $i => $field): ?>
		<tr>
			<td><?php echo $form->textField($field, '[' . $i . ']name', array('size' => '20')); ?></td>
			<td><?php echo $form->dropDownList($field, '[' . $i . ']type', $field->typeOptions()); ?></td>
			<td><?php echo $form->dropDownList($field, '[' . $i . ']index', $field->indexOptions()); ?></td>
			<td><?php echo $form->dropDownList($field, '[' . $i . ']tokenizer', $field->tokenizerOptions()); ?></td>
			<td><?php echo $form->textField($field, '[' . $i . ']cutlen', array('size' => '4')); ?></td>
			<td><?php echo $form->textField($field, '[' . $i . ']weight', array('size' => '4')); ?></td>
			<td><?php echo $form->dropDownList($field, '[' . $i . ']phrase', $field->phraseOptions()); ?></td>
		</tr>
		<?php endforeach; ?>
	</table>
	<div class="row-fluid">
		<div class="span12 text-right">
			<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => '保存结构')); ?>
			<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'button', 'label' => '添加字段', 'id' => 'btn-add')); ?>
		</div>
    </div>
	<?php $this->endWidget(); ?>
</div>
<?php $this->endWidget();?>
<script type="text/javascript" pos="ready">
	$('#btn-add').click(function(){
		$table = $('#field-table');
		var i = $table.find('tr').size();
		var html = $table.find('tr:last').html();
		html = html.replace(/FieldForm([_\[])\d+/g, 'FieldForm$1' + i);
		$table.append('<tr>' + html + '</tr>');
	});
</script>
